/* SPDX-License-Identifier: GPL-2.0 */
/* smc-app.h - the command application for SMC
 *
 * Copyright (C) 2016-2018, LomboTech Co.Ltd.
 * Author: lomboswer <lomboswer@lombotech.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#define LC_MAX		255
#define LE_MAX		255
#define MAX_LEN		255
#define ERROR		-1
#define CONTACT_NAME_MAX	14
#define CONTACT_NUMBER_MAX	11
#define MESSAGE_MAX		176

#define SIM_NORMAL_CLASS			(0xA0)

#define SIM_CMD_STATUS_INST			(0xF2)
#define SIM_CMD_STATUS_DATA_LEN			(0x00)
#define SIM_CMD_STATUS_FRAME_LEN		(0x05)

#define SIM_CMD_SELECT_INST			(0xA4)
#define SIM_CMD_SELECT_DATA_LEN			(0x02)
#define SIM_CMD_SELECT_HEADER_LEN		(0x05)
#define SIM_CMD_SELECT_BODY_LEN			(0x02)
#define SIM_CMD_SELECT_FRAME_LEN		(0x07)

#define SIM_CMD_READ_BINARY_INST		(0xB0)
#define SIM_CMD_READ_BINARY_DATA_LEN		(0x0A)
#define SIM_CMD_READ_BINARY_FRAME_LEN		(0x05)

#define SIM_CMD_UPDATE_BINARY_INST		(0xD6)
#define SIM_CMD_UPDATE_BINARY_DATA_LEN		(0x0A)
#define SIM_CMD_UPDATE_BINARY_FRAME_LEN		(0x05)

#define SIM_CMD_READ_RECORD_INST		(0xB2)
#define SIM_CMD_READ_RECORD_DATA_LEN		(0x0A)
#define SIM_CMD_READ_RECORD_FRAME_LEN		(0x05)

#define SIM_CMD_UPDATE_RECORD_INST		(0xDC)
#define SIM_CMD_UPDATE_RECORD_LEN		(0x0A)
#define SIM_CMD_UPDATE_RECORD_FRAME_LEN		(0x05)

#define SIM_CMD_GET_RESPONSE_INST		(0xC0)
#define SIM_CMD_GET_RESPONSE_DATA_LEN		(0x00)
#define SIM_CMD_GET_RESPONSE_FRAME_LEN		(0x05)


#define SIM_FILE_ID_MF				(0x3F00)
#define SIM_FILE_ID_DF_TELECOM			(0x7F10)
#define SIM_FILE_ID_DF_GSM			(0x7F20)

#define SIM_FILE_ID_EF_ICCID			(0x2FE2)
#define SIM_FILE_ID_EF_ELP			(0x2F05)
#define SIM_FILE_ID_EF_IMSI			(0x6F07)
#define SIM_FILE_ID_EF_ADN			(0x6F3A)
#define SIM_FILE_ID_EF_FDN			(0x6F3B)
#define SIM_FILE_ID_EF_SMS			(0x6F3C)
#define SIM_FILE_ID_EF_LP			(0x6F05)


struct smc_header {
	u8 cla; // command class
	u8 ins; // instuction
	u8 p1;  // p1
	u8 p2;  // p2
	u8 p3;	// p3, indicate body data len
};

struct smc_body {
//	u8 lc;			// command length
	u8 data[LC_MAX];	// data field
//	u8 le;			// response length
};

struct smc_apdu_command {
	struct smc_header header;
	struct smc_body	body;
};

struct smc_apdu_response {
	u8 data[LE_MAX];	// data field
//	u8 sw1;			// status
//	u8 sw2;			// status
};

struct ATR {
	u8 TS;
	u8 T0;
	u8 TA[8];
	u8 TB[8];
	u8 TC[8];
	u8 TD[8];
	u8 HistoricalLength;
	u8 Historical[15];
	u8 TCK;
};


extern int smc_reset_select_directory(void);
